'use strict';
/* jshint mocha: true */

var path = require('path');
var expect = require('chai').expect;
var Injector = require('injector');

var projectPath = path.resolve(__dirname, '..');
var includePaths = [projectPath + '/lib', projectPath + '/example'];

describe('test/test_static', function () {
    it('#new AppError', function () {
        function test(AppError) {
            expect(AppError).to.be.a('function');
            expect(function () {
                var appError = new AppError();
                expect(appError).to.be.a('object');
            }).to.throw('The parameter <code>');
            expect(function () {
                var appError = new AppError('1');
                expect(appError).to.be.a('object');
                expect(appError.getCode()).to.equal('1');
                expect(appError.getMessage()).to.be.an('undefined');
                expect(appError.getData()).to.be.an('undefined');
                expect(appError.getMeta()).to.be.an('undefined');
            }).to.not.throw(Error);
            expect(function () {
                var appError = new AppError('1', 'a', 'b', 'c');
                expect(appError).to.be.a('object');
                expect(appError.getCode()).to.equal('1');
                expect(appError.getMessage()).to.equal('a');
                expect(appError.getData()).to.equal('b');
                expect(appError.getMeta()).to.equal('c');
            }).to.not.throw(Error);
        }
        var injector = new Injector(includePaths, {});
        var moduleDefinition = Injector.define([
            'component/app_error'
        ], test);
        injector.inject(moduleDefinition);
    });
    it('#appError.setMessage/getMessage', function () {
        function test(AppError) {
            var appError = new AppError(1);
            expect(appError.getMessage()).to.equal(undefined);
            appError.setMessage('message1');
            expect(appError.getMessage()).to.equal('message1');
            appError.setMessage(undefined);
            expect(appError.getMessage()).to.equal(undefined);
            appError.setMessage({message:'message2'});
            expect(appError.getMessage()).to.equal('message2');
            appError.setMessage({message1:'message3'});
            expect(appError.getMessage()).to.equal(undefined);
            appError.setMessage({message:[]});
            expect(appError.getMessage()).to.equal(undefined);
            appError.setMessage({getMessage:function () {
                return 'message4';
            }});
            expect(appError.getMessage()).to.equal('message4');
            appError.setMessage({getMessage:function () {
                return [];
            }});
            expect(appError.getMessage()).to.equal(undefined);
        }
        var injector = new Injector(includePaths, {});
        var moduleDefinition = Injector.define([
            'component/app_error'
        ], test);
        injector.inject(moduleDefinition);
    });
    it('#appError.getCode', function () {
        function test(AppError) {
            var appError = new AppError(1);
            expect(appError.getCode()).to.equal(1);
            var appError = new AppError('1');
            expect(appError.getCode()).to.equal('1');
        }
        var injector = new Injector(includePaths, {});
        var moduleDefinition = Injector.define([
            'component/app_error'
        ], test);
        injector.inject(moduleDefinition);
    });
    it('#appError.setData/getData', function () {
        function test(AppError) {
            var appError = new AppError(1);
            expect(appError.getData()).to.equal(undefined);
            var data = {};
            appError.setData(data);
            expect(appError.getData()).to.equal(data);
        }
        var injector = new Injector(includePaths, {});
        var moduleDefinition = Injector.define([
            'component/app_error'
        ], test);
        injector.inject(moduleDefinition);
    });
    it('#appError.setMeta/getMeta', function () {
        function test(AppError) {
            var appError = new AppError(1);
            expect(appError.getMeta()).to.equal(undefined);
            var data = {};
            appError.setMeta(data);
            expect(appError.getMeta()).to.equal(data);
        }
        var injector = new Injector(includePaths, {});
        var moduleDefinition = Injector.define([
            'component/app_error'
        ], test);
        injector.inject(moduleDefinition);
    });
    it('#appError.toJson', function () {
        function test(AppError) {
            var appError = new AppError(1, 'a', 'b', {c:'c'});
            expect(appError.toJson()).to.deep.equal({
                c: 'c',
                code: 1,
                message: 'a',
                data: 'b'
            });
        }
        var injector = new Injector(includePaths, {});
        var moduleDefinition = Injector.define([
            'component/app_error'
        ], test);
        injector.inject(moduleDefinition);
    });
    it('#appError.toJsonString', function () {
        function test(AppError) {
            var appError = new AppError(1, 'a', 'b', {c:'c'});
            expect(appError.toJsonString()).to.equal(JSON.stringify({
                c: 'c',
                code: 1,
                message: 'a',
                data: 'b'
            }));
        }
        var injector = new Injector(includePaths, {});
        var moduleDefinition = Injector.define([
            'component/app_error'
        ], test);
        injector.inject(moduleDefinition);
    });

});